'''
 * @ author     ：廖传港
 * @ date       ：Created in 2020/11/6 11:14
 * @ description：
 * @ modified By：
 * @ ersion     : 
 * @File        : train.py 
'''

from com.lcg.version12 import Loading_pictures as lp
import numpy as np
from com.lcg.version12 import model as md
# from com.lcg.version12 import dl9 as md
import joblib
from keras.utils import to_categorical

# 总数
count = 200
debug = 0


# 加载数据集
def Loaddata():


    # 加载数据集
    X, Y = lp.loaddata("D:/python/data/data4/")

    # # reshape：改变数组维数 重新塑造 矩阵变维
    # XX = np.reshape(train_images, (60000, 22, 22))
    # X = np.array(XX[0:count, :])


    # Y = to_categorical(Y)  #将标签转换为分类的 one-hot 编码

    return X, Y



if __name__ == '__main__':

    X,Y=Loaddata()
    print("Y:",Y.shape)
    print("X:",X.shape)
 
    #---------训练1--------------
    dnn = md.DNN()
    dnn.Add(md.CNN2D_MultiLayer(4, 4, 2, 10))  # 卷积
    dnn.Add(md.DMaxPooling2D(2, 2)) # 池化
    dnn.Add(md.CNN2D_MultiLayer(2, 2, 1, 5)) # 卷积
    dnn.Add(md.DMaxPooling2D(2, 2))  # 池化
    dnn.Add(md.DFlatten())  #扁平化，把数据拉成条
    dnn.Add(md.DDense(10, 'relu'))  # 全连接
    dnn.Add(md.DDense(1, 'sigmoid'))  # 全连接

    dnn.Compile()
    dnn.Fit(X[0:150,:], Y[0:150], 100)
    # dnn.Fit(X, Y, 100)
    # 将模型持久化保存
    joblib.dump(dnn, "D:/python/data/model/model3.model")